package com.amap.api.col.s;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import com.amap.api.col.s.cf;
import com.amap.api.col.s.y;
import com.amap.api.services.core.AMapException;
import com.amap.api.services.interfaces.IRoutePOISearch;
import com.amap.api.services.routepoisearch.RoutePOISearch;
import com.amap.api.services.routepoisearch.RoutePOISearchQuery;
import com.amap.api.services.routepoisearch.RoutePOISearchResult;

/* compiled from: RoutePOISearchCore.java */
/* loaded from: classes.dex */
public final class bq implements IRoutePOISearch {
    private RoutePOISearchQuery a;
    private Context b;
    private RoutePOISearch.OnRoutePOISearchListener c;
    private Handler d;

    public bq(Context context, RoutePOISearchQuery routePOISearchQuery) throws AMapException {
        this.d = null;
        cg a = cf.a(context, m.a(false));
        if (a.a != cf.c.SuccessCode) {
            throw new AMapException(a.b, 1, a.b, a.a.a());
        }
        this.b = context;
        this.a = routePOISearchQuery;
        this.d = y.a();
    }

    @Override // com.amap.api.services.interfaces.IRoutePOISearch
    public final void setRoutePOISearchListener(RoutePOISearch.OnRoutePOISearchListener onRoutePOISearchListener) {
        this.c = onRoutePOISearchListener;
    }

    @Override // com.amap.api.services.interfaces.IRoutePOISearch
    public final void searchRoutePOIAsyn() {
        ax.a().a(new Runnable() { // from class: com.amap.api.col.s.bq.1
            {
                bq.this = this;
            }

            @Override // java.lang.Runnable
            public final void run() {
                y.m mVar;
                Message obtainMessage = bq.this.d.obtainMessage();
                obtainMessage.arg1 = 14;
                Bundle bundle = new Bundle();
                RoutePOISearchResult routePOISearchResult = null;
                try {
                    try {
                        routePOISearchResult = bq.this.searchRoutePOI();
                        bundle.putInt("errorCode", 1000);
                        mVar = new y.m();
                    } catch (AMapException e) {
                        bundle.putInt("errorCode", e.getErrorCode());
                        mVar = new y.m();
                    }
                    mVar.b = bq.this.c;
                    mVar.a = routePOISearchResult;
                    obtainMessage.obj = mVar;
                    obtainMessage.setData(bundle);
                    bq.this.d.sendMessage(obtainMessage);
                } catch (Throwable th) {
                    y.m mVar2 = new y.m();
                    mVar2.b = bq.this.c;
                    mVar2.a = routePOISearchResult;
                    obtainMessage.obj = mVar2;
                    obtainMessage.setData(bundle);
                    bq.this.d.sendMessage(obtainMessage);
                    throw th;
                }
            }
        });
    }

    @Override // com.amap.api.services.interfaces.IRoutePOISearch
    public final void setQuery(RoutePOISearchQuery routePOISearchQuery) {
        this.a = routePOISearchQuery;
    }

    @Override // com.amap.api.services.interfaces.IRoutePOISearch
    public final RoutePOISearchQuery getQuery() {
        return this.a;
    }

    @Override // com.amap.api.services.interfaces.IRoutePOISearch
    public final RoutePOISearchResult searchRoutePOI() throws AMapException {
        try {
            w.a(this.b);
            if (!a()) {
                throw new AMapException(AMapException.AMAP_CLIENT_INVALID_PARAMETER);
            }
            return new at(this.b, this.a.m34clone()).c();
        } catch (AMapException e) {
            n.a(e, "RoutePOISearchCore", "searchRoutePOI");
            throw e;
        }
    }

    private boolean a() {
        RoutePOISearchQuery routePOISearchQuery = this.a;
        if (routePOISearchQuery == null || routePOISearchQuery.getSearchType() == null) {
            return false;
        }
        return (this.a.getFrom() == null && this.a.getTo() == null && this.a.getPolylines() == null) ? false : true;
    }
}
